package org.phoenixframework.common.tools;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

/**
 * Created by IntelliJ IDEA.
 *
 * @author doublelifeke
 * Email: hautxxxyzjk@163.com
 * DateTime: 2021/2/27 18:12
 * Description:
 */
public class PhoenixUtil {

    /**
     * 判断字符串是否全是中文
     * @param str
     * @return
     */
    public static boolean isAllChinese(String str) {
        if (str == null) {
            return false;
        }
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]+");
        Matcher m = p.matcher(str);
        return m.matches();
    }

    /**
     * 判断字符串中是否包含中文
     *
     * @param str 待校验字符串
     * @return 是否为中文
     * @warn 不能校验是否为中文标点符号
     */
    public static boolean isContainsChinese(String str) {
        if (str == null) { return false; }
        Pattern p = Pattern.compile("[\u4e00-\u9fa5]");
        Matcher m = p.matcher(str);
        return m.find();
    }

    public static void main(String[] args) {
        String str = "吴进1";
        boolean containsChinese = isContainsChinese(str);
        System.out.println(containsChinese);
    }

}
